//
//  main.m
//  04_容器类
//
//  Created by dllo on 16/7/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Contact.h"
#import "ContactManager.h"

int main(int argc, const char * argv[]) {
    
#if 0
    // 1.字典
    // 存储键值对,存储数据没有顺序,通过key存储,查询value
    // 1>初始化
    // 字典中只能存放对象类型(NSObject子类)
    // 如果出现汉字,代码提示一定会失效
    NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"李四", @"name", [NSNumber numberWithInt: 18], @"age", nil];
    // 2>构造器
    NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@"李四", @"name", [NSNumber numberWithInt: 18], @"age", nil];
    // 3>字面量,推荐使用字面量
    NSDictionary *dictionary = @{@"name": @"含蓄",
                                  @"age": @(-18)};
    // 4>取值
    //  <1>取value
    NSString *name = [dictionary objectForKey:@"name"];
    //  <2>取所有的key和value
    // Keys和Values是复数,大概是数组
    NSArray *allKeys = dictionary.allKeys;
    NSArray *allValues = dictionary.allValues;
    //  <3>count
    NSUInteger count = dictionary.count;
    //  <4>通过一个key数组取到对应value的数组,如没有找到,那没有找到的元素类型为NSString类型
    NSArray *allValueArray = [dictionary objectsForKeys:@[@"age"] notFoundMarker:[NSString class]];
    NSLog(@"%@", allValueArray);
    //  <5>相同value的所有key的数组
    NSArray *keyArray = [dic1 allKeysForObject:@"含蓄"];
    NSLog(@"%@", keyArray);
    //  <6>语法糖取值
    NSLog(@"%@", dic[@"name"]);
    
    // 可变字典 NSMutableDictionary, 不推荐使用字面量
    NSMutableDictionary *mutableDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"含蓄", @"name", nil];
    NSMutableDictionary *mutatleDic1 = [@{} mutableCopy];   // 不推荐这样写
    
    // 增 删 改
    // 1>添加:如果key值已经存在,会将之前的value覆盖
    // 字典中的key不要重复,如果重复,会以最后的value进行赋值
    [mutableDic setObject:@"起名好难" forKey:@"name"];
    NSLog(@"%@", mutableDic);
    // 2>删除
    [mutableDic removeObjectForKey:@"name"];
    [mutableDic removeAllObjects];
    NSLog(@"%@", mutableDic);
    // 3>语法糖
    mutableDic[@"name"] = @"历程";    // 相当于setObject:forKey:
#endif
    

#if 1
    Contact *c1 = [[Contact alloc] initWithName:@"shixiaoqi" phoneNumber:@"15041780713"];
    [c1 showContact];
    NSLog(@"%@", c1);
    
    Contact *c2 = [[Contact alloc] initWithName:@"雨涵" phoneNumber:@"11111"];
    Contact *c3 = [[Contact alloc] initWithName:@"liuhe" phoneNumber:@"222222"];
    Contact *c4 = [[Contact alloc] initWithName:@"mengjie" phoneNumber:@"33333"];
    Contact *c5 = [[Contact alloc] initWithName:@"sihongyang" phoneNumber:@"44444"];
    Contact *c6 = [[Contact alloc] initWithName:@"yuchenjing" phoneNumber:@"55555"];
    Contact *c7 = [[Contact alloc] initWithName:@"dongqianjin" phoneNumber:@"666666"];
    
    ContactManager *contactManager = [[ContactManager alloc] initWithDictionary:[NSMutableDictionary dictionary]];
    [contactManager addContact:c1];
    [contactManager addContact:c2];
    [contactManager addContact:c3];
    [contactManager addContact:c4];
    [contactManager addContact:c5];
    [contactManager addContact:c6];
    [contactManager addContact:c7];
    
    NSLog(@"%@", contactManager.contactDictionary);
    
    // description的作用:将调用者转换为字符串.
    NSNumber *number = [NSNumber numberWithInteger:10];
    NSString *numberStr = number.stringValue;
    [@10 description];
#endif
    
#if 0
    // 2.集合
    // NSSet, NSMutableSet
    // 1>初始化
    // 集合会删除掉重复的内容,互异性.
    // 应用:删除数组中重复的内容
    NSSet *set = [[NSSet alloc] initWithObjects:@"hanxu", @"hanxu", nil];
    NSLog(@"%@", set);
    // 2>构造器
    // 3>系统没有提供集合的字面量
    // 4>取值,从集合中取出任意元素,无序
    NSString *str = [set anyObject];
    // 5>count
    NSLog(@"%lu", set.count);
    
    NSArray *repeatArray = @[@10, @20, @10, @30, @100, @10];
    NSLog(@"%@", repeatArray);
    NSSet *repeatSet = [NSSet setWithArray:repeatArray];
    NSLog(@"%@", repeatSet);
    
    // 可变集合 NSMutableSet
#endif
    
    return 0;
}
